home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / drivers / et4000.asm < prev    next >
Assembly Source File  |  1993-12-06  |  13KB  |  428 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file ET4000.ASM
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ;
  7. ; This file is distributed under the terms listed in the document
  8. ; "copying.dj", available from DJ Delorie at the address above.
  9. ; A copy of "copying.dj" should accompany this file; if not, a copy
  10. ; should be available from where this file was obtained.  This file
  11. ; may not be distributed without a verbatim copy of "copying.dj".
  12. ;
  13. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  14. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. ;--------------------------------------------------------------------------
  16.  
  17. include grdriver.inc
  18.  
  19. ;
  20. ; Use GRD_8_F_PLANES for the faster planar block fills (VGA only!!!!!)
  21. ; Use GRD_8_PLANES   if it does not work or on non-VGA (accelerated) cards
  22. ;
  23. C_256_M equ    GRD_8_F_PLANES
  24.  
  25.  
  26. cseg    segment byte public 'code'
  27.     assume  cs:cseg, ds:cseg, es:cseg, ss:nothing
  28.  
  29.  
  30. ;--------------------------------------------------------------------------
  31. ; DRIVER HEADER
  32. ;  The following entries MUST match the structure and constant
  33. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  34. ;  The mode word should contain the following bitfields:
  35. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  36. ;     - the adapter type field should be specified
  37. ;     - the memory size field should be specified
  38. ;     - the paging mode field should be specified
  39. ;  The mode set routine will OR in the plane bitfield as it will
  40. ;  change when different color number modes are requested.
  41. ;--------------------------------------------------------------------------
  42.  
  43.     dw    offset mode_set_routine
  44.     dw    offset paging_routine
  45. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_1024K+GRD_RW_64K
  46. ;
  47. ; The 'def_xx' fields are filled in by go32 from the corresponding
  48. ; fields of the 'GO32' environment variable
  49. ;
  50. def_tw  dw    80        ; text width
  51. def_th  dw    25        ; text height
  52. def_gw  dw    640        ; graphics width
  53. def_gh  dw    480        ; graphics height
  54. def_nc  dw    16        ; graphics colors
  55.     dw    offset driver_init_routine
  56.     dw    offset text_mode_table
  57.     dw    offset graphics_mode_table
  58.  
  59. ;
  60. ; Biggest text and graphics sizes
  61. ;
  62. Max_TW  equ    132
  63. Max_TH  equ    50
  64. Max_GWn equ    800        ; non interlaced!!!
  65. Max_GHn equ    600
  66. Max_GW  equ    1024        ; may be interlaced
  67. Max_GH  equ    768
  68.  
  69.  
  70. ;--------------------------------------------------------------------------
  71. ; TABLE OF SUPPORTED TEXT MODES
  72. ;    - keep sorted by size
  73. ;    - end with an all 0 entry
  74. ;    - BIOS field = 0xff disables it
  75. ;    - fields:
  76. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  77. ;--------------------------------------------------------------------------
  78. text_mode_table        label word
  79.     dw    80,    25,    2,    007h +  00000h
  80.     dw    40,    25,    16,    001h +  00000h
  81.     dw    80,    25,    16,    003h +  00000h
  82.     dw    80,    50,    16,    003h +  00100h
  83.     dw    100,    40,    16,    02ah +  00000h
  84.     dw    132,    25,    16,    023h +  00000h
  85.     dw    132,    28,    16,    024h +  00000h
  86.     dw    132,    44,    16,    022h +  00000h
  87. ;    dw    132,    50,    16,    061h +  00000h
  88.     dw    0,    0,    0,    000h +  00000h
  89.  
  90.  
  91. ;--------------------------------------------------------------------------
  92. ; TABLE OF SUPPORTED GRAPHICS MODES
  93. ;    - keep sorted first by colors then by size
  94. ;    - end with an all 0 entry
  95. ;    - BIOS field = 0xff disables it
  96. ;    - fields:
  97. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  98. ;--------------------------------------------------------------------------
  99. graphics_mode_table    label word
  100.     dw    320,    200,    16,    00dh +  00000h
  101.     dw    640,    200,    16,    00eh +  00000h
  102.     dw    640,    350,    16,    010h +  00000h
  103.     dw    640,    480,    16,    012h +  00000h
  104.     dw    800,    600,    16,    029h +  00000h
  105.     dw    1024,    768,    16,    037h +  00000h
  106.     dw    320,    200,    256,    013h +  00000h
  107.     dw    640,    350,    256,    02dh +  00000h
  108.     dw    640,    480,    256,    02eh +  00000h
  109.     dw    800,    600,    256,    030h +  00000h
  110.     dw    1024,    768,    256,    038h +  00000h
  111. ET4000_HiColor_Table    label word
  112.     dw    640,    350,    32768,  02dh +  00200h  ; HiColor
  113.     dw    640,    480,    32768,  02eh +  00200h  ; HiColor
  114.     dw    800,    600,    32768,  030h +  00200h  ; HiColor
  115. ET4000_HiColor_EndTable label word
  116.     dw    0,    0,    0,    000h +  00000h
  117.  
  118.  
  119. ;--------------------------------------------------------------------------
  120. ; TABLE OF SPECIAL SETUP PROCEDURES
  121. ;  You may need such procedures for:
  122. ;     -- reloading fonts on standard EGA or VGA for
  123. ;     higher resolution text modes
  124. ;     -- enable HiColor mode of some Super VGAs
  125. ;     -- Handle the parameter passing conventions of the VESA BIOS
  126. ;     -- put VGA into 256 color plane mode ("MODE X")
  127. ;     -- etc...
  128. ;  There should be one entry in the table for every non-zero
  129. ;  'setup_procedure_index' in the text and graphics mode tables.
  130. ;  The first entry in the table belongs to index 100h, and so on.
  131. ;  The special setup procedure is invoked via a near call.
  132. ;
  133. ;  Entry: DI=address of the mode record from the text or graphics
  134. ;      table to set up.
  135. ;
  136. ;  Exit:  Adapter configured
  137. ;      BX=driver mode word as it should be returned by the mode set
  138. ;         routine. Typically it involves picking up the mode word
  139. ;         from the header and OR-ing in the appropriate bitplane mode
  140. ;         bitfield. (This is not needed for text modes)
  141. ;      AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  142. ;
  143. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  144. ;--------------------------------------------------------------------------
  145. special_setup_table    label word
  146.     dw    offset  VGA_50row_mode_set
  147.     dw    offset  ET4000_HiColor_setup
  148.  
  149. ;
  150. ; Routine to set up VGA 50 row mode
  151. ; interface is described above
  152. ;
  153. VGA_50row_mode_set    proc    near
  154.     mov    ax,03h            ; set 80x25 mode
  155.     int    10h
  156.     xor    bx,bx
  157.     mov    ax,1112h        ; load 8x8 font
  158.     int    10h
  159.     ret
  160. VGA_50row_mode_set    endp
  161.  
  162. ;
  163. ; Routine to set up ET4000 HiColor modes
  164. ; interface is described above
  165. ;
  166. ET4000_HiColor_setup    proc    near
  167.     mov    al,BYTE PTR [di+6]    ; set up 256 colors w/ same WxH
  168.     xor    ah,ah
  169.     int    10h
  170.     mov    ax,10f0h
  171.     mov    bl,BYTE PTR [di+6]
  172.     int    10h            ; set up HiColor w/ same size
  173.     cmp    ax,10h            ; success ?
  174.     je    ET4000_HiColor_Success
  175.     mov    al,BYTE PTR [di+6]    ; go with the 256 color mode!
  176.     xor    ah,ah
  177.     int    10h
  178.     mov    BYTE PTR [di+6],0ffh;    ; disable this entry
  179.     mov    bx,C_256_M
  180.     jmp    ET4000_HiColor_EndProc
  181. ET4000_HiColor_Success:
  182.     mov    bx,GRD_16_PLANES
  183. ET4000_HiColor_EndProc:
  184.     or    bx,mode_W
  185.     ret
  186. ET4000_HiColor_setup    endp
  187.  
  188.  
  189. ;--------------------------------------------------------------------------
  190. ; DRIVER INIT ROUTINE
  191. ;  called once after the driver is loaded
  192. ;  may do one or more of the followings:
  193. ;    - check for proper board type
  194. ;    - check amount of RAM on board, and:
  195. ;    -- update word in header to reflect correct amount
  196. ;    -- disable modes in the tables for which there is not enough RAM
  197. ;    - check for special equipment (HiColor DAC, etc...)
  198. ;
  199. ;  Entry: nothing
  200. ;
  201. ;  Exit:  AX=status:
  202. ;       non-zero: OK,
  203. ;       0: something went wrong (e.g. wrong adapter, etc..)
  204. ;      BX,CX,DX may be trashed
  205. ;
  206. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  207. ;--------------------------------------------------------------------------
  208. driver_init_routine    proc    far
  209.     mov    ax,10f1h        ; get DAC type
  210.     int    10h
  211.     cmp    ax,10h
  212.     jne    no_HiColor
  213.     cmp    bl,1
  214.     jmp    have_HiColor
  215. no_HiColor:
  216.     mov    bx,offset ET4000_HiColor_Table
  217. kill_HiColor:
  218.     mov    BYTE PTR [bx+6],0ffh;    ; invalidate mode entry
  219.     add    bx,8
  220.     cmp    bx,offset ET4000_HiColor_EndTable
  221.     jne    kill_HiColor
  222. have_HiColor:
  223.     mov    ax,1
  224.     ret
  225. driver_init_routine    endp
  226.  
  227.  
  228. ;--------------------------------------------------------------------------
  229. ; MODE SET ROUTINE
  230. ;  sets up a text or graphics mode as close as possible to the one
  231. ;  reguested by the user with regard to number of colors and size.
  232. ;
  233. ;  Entry: AX=mode selection
  234. ;     0 = 80x25 text
  235. ;     1 = default text
  236. ;     2 = text CX cols by DX rows
  237. ;     3 = biggest text
  238. ;     4 = 320x200 graphics
  239. ;     5 = default graphics
  240. ;     6 = graphics CX width by DX height
  241. ;     7 = biggest non-interlaced graphics
  242. ;     8 = biggest graphics
  243. ;     9 = graphics BX colors, CX width by DX height
  244. ;
  245. ;  Exit: BX=driver mode flag
  246. ;     CX=width (in pixels or characters)
  247. ;     DX=height
  248. ;
  249. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  250. ;     YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  251. ;     MUCH TABLE DRIVEN
  252. ;--------------------------------------------------------------------------
  253. mode_set_routine    proc    far
  254.     push    ds
  255.     push    di
  256.     push    si
  257.     mov    si,cs
  258.     mov    ds,si
  259.     cmp    ax,9
  260.     jbe    DoIt
  261.     jmp    Exit
  262. DoIt:    add    ax,ax
  263.     mov    si,ax
  264.     jmp    WORD PTR mode_set_table[si]
  265. mode_set_table  label    word
  266.     dw    offset mode_0
  267.     dw    offset mode_1
  268.     dw    offset mode_2
  269.     dw    offset mode_3
  270.     dw    offset mode_4
  271.     dw    offset mode_5
  272.     dw    offset mode_6
  273.     dw    offset mode_7
  274.     dw    offset mode_8
  275.     dw    offset mode_9
  276. mode_0: mov    si,offset text_mode_table    ; 80x25 text
  277.     mov    bx,def_nc
  278.     mov    cx,80
  279.     mov    dx,25
  280.     jmp    Lookup
  281. mode_1: mov    si,offset text_mode_table    ; default text
  282.     mov    bx,def_nc
  283.     mov    cx,def_tw
  284.     mov    dx,def_th
  285.     jmp    Lookup
  286. mode_2: mov    si,offset text_mode_table    ; CX*DX text
  287.     mov    bx,def_nc
  288.     jmp    Lookup
  289. mode_3: mov    si,offset text_mode_table    ; biggest text
  290.     mov    bx,def_nc
  291.     mov    cx,Max_TW
  292.     mov    dx,Max_TH
  293.     jmp    Lookup
  294. mode_4: mov    si,offset graphics_mode_table    ; 320x200 graphics
  295.     mov    bx,def_nc
  296.     mov    cx,320
  297.     mov    dx,200
  298.     jmp    Lookup
  299. mode_5: mov    si,offset graphics_mode_table    ; default graphics
  300.     mov    bx,def_nc
  301.     mov    cx,def_gw
  302.     mov    dx,def_gh
  303.     jmp    Lookup
  304. mode_6: mov    si,offset graphics_mode_table    ; CX*DX graphics
  305.     mov    bx,def_nc
  306.     jmp    Lookup
  307. mode_7: mov    si,offset graphics_mode_table    ; biggest non-interlaced gr
  308.     mov    bx,def_nc
  309.     mov    cx,Max_GWn
  310.     mov    dx,Max_GHn
  311.     jmp    Lookup
  312. mode_8: mov    si,offset graphics_mode_table    ; biggest graphics
  313.     mov    bx,def_nc
  314.     mov    cx,Max_GW
  315.     mov    dx,Max_GH
  316.     jmp    Lookup
  317. mode_9: mov    si,offset graphics_mode_table    ; CX*DX graphics w/ BX colors
  318. ;
  319. ; At this point:
  320. ;   SI points to the table to search (text or graphics)
  321. ;   BX has colors
  322. ;   CX has width
  323. ;   DX has height
  324. ;
  325. Lookup: xor    ax,ax                ; last color number seen
  326. Find_C: cmp    [si+4],ax            ; last color number == this?
  327.     je    Same_C
  328.     jb    Prev_C                ; end of table -- use last color
  329.     cmp    BYTE PTR [si+6],0ffh        ; valid entry ?
  330.     je    Prev_C                ; not -- use last color
  331.     mov    ax,[si+4]            ; record color number
  332.     mov    di,si                ; start of entries w/ this color
  333.     cmp    ax,bx                ; enough colors ?
  334.     jae    Find_S
  335. Same_C: add    si,8
  336.     jmp    Find_C
  337. Prev_C: or    ax,ax                ; found any color at all?
  338.     je    Exit
  339. ;
  340. ; At this point:
  341. ;   DI points into the table to the first entry with the desired color
  342. ;      number (either it has enough colors or it is the highest color
  343. ;      number supported by the driver). Additionally, at least the
  344. ;      first (= smallest size) entry for this color is valid (has a
  345. ;      valid BIOS number).
  346. ;   AX has the color number adjusted for the driver
  347. ;   CX has width
  348. ;   DX has height
  349. ;
  350. Find_S: cmp    [di+4],ax            ; still the same color #?
  351.     jne    Prev_S
  352.     cmp    BYTE PTR [di+6],0ffh        ; valid entry ?
  353.     je    Prev_S
  354.     cmp    [di],cx
  355.     jb    Next_S
  356.     cmp    [di+2],dx
  357.     jae    GotIt
  358. Next_S: add    di,8
  359.     jmp    Find_S
  360. Prev_S: sub    di,8
  361. ;
  362. ; At this point:
  363. ;   DI points to the table entry we want to set up
  364. ;
  365. GotIt:  mov    ax,[di+6]            ; BIOS mode number
  366.     or    ah,ah                ; special ?
  367.     je    doBIOS
  368.     mov    al,ah
  369.     xor    ah,ah
  370.     dec    ax
  371.     add    ax,ax
  372.     mov    si,ax
  373.     call    WORD PTR special_setup_table[si]
  374.     jmp    RetVal
  375. doBIOS: int    10h
  376.     mov    bx,GRD_1_PLANE
  377.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  378.     je    doFLAG
  379.     mov    bx,GRD_4_PLANES
  380.     cmp    WORD PTR [di+4],16        ; 16 colors ?
  381.     je    doFLAG
  382.     mov    bx,C_256_M
  383.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  384.     je    doFLAG
  385.     mov    bx,GRD_16_PLANES
  386.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  387.     je    doFLAG
  388.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  389. doFLAG: or    bx,mode_W
  390. RetVal: mov    cx,[di]
  391.     mov    dx,[di+2]
  392. Exit:    pop    si
  393.     pop    di
  394.     pop    ds
  395.     ret
  396. mode_set_routine    endp
  397.  
  398.  
  399. ;--------------------------------------------------------------------------
  400. ; PAGING ROUTINE
  401. ;
  402. ;  Entry: AH=read page
  403. ;      AL=write page
  404. ;
  405. ;  Exit: VGA configured.
  406. ;     AX,BX,CX,DX,SI,DI may be trashed
  407. ;
  408. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  409. ;     This code must be relocatable and may not reference any data!
  410. ;--------------------------------------------------------------------------
  411.     assume  ds:nothing, es:nothing
  412.  
  413. paging_routine  proc    far
  414.     and    al,0fh
  415.     mov    cl,4
  416.     shl    ah,cl
  417.     and    ah,0f0h
  418.     or    al,ah
  419.     mov    dx,03cdh
  420.     out    dx,al
  421.     ret
  422. paging_routine  endp
  423.  
  424.  
  425. cseg    ends
  426.     end
  427.  
  428.